<?php
	//read th sitename of the Joomla! Management Instance
	$conf =& JFactory::getConfig();
	$sitename = $conf->getValue('config.sitename');
?>
<h1>Extension Overview</h1>
<form name="adminForm" id="adminForm" method="post" action="<?php echo JRoute::_('index.php?option=com_easiv2&view=manageExtensions');?>">
	<table class="adminlist">
		<thead>
			<tr>
				<th width="200"><?php echo JText::_('Extension'); ?></th>
				<?php
					echo "<th>".$sitename."<br><input type=\"checkbox\" name=\"CHECKALL\" /></th>";
					
					foreach($this->remoteInstanceObjects as $inst) {
						//echo "<th width=\"100\">".$inst->name."<br><input type=\"checkbox\" name=\"toggle\" value=\"\" onclick=\"checkAll(".count($this->extensions).");\" /></th>";
						echo "<th>".$inst->name."<br><input type=\"checkbox\" name=\"CHECKALL\" /></th>";
					}	
				?>
			</tr>
		</thead>
		<tbody>
			<?php
				/**
				 * AAAAAHHHHH!!!!
				 */
				foreach($this->extensions as $ext) {
					echo "<tr>
							<td>".$ext->extension." v".$ext->version."</td>";
					
						//check local install status and define correct image and message
						if($this->localInstallStatus[$ext->extension] == "true") {
							$image = "<img src=\"components/com_easiv2/images/true.png\" />";
						}
						else {
							$image = "<img src=\"components/com_easiv2/images/false.png\" />";
						}
						
						echo "<td align=\"center\" valign=\"middle\"><input type=\"checkbox\" name=\"selected[]\" value=\"".$ext->extension.":LOCAL:".$this->localInstallStatus[$ext->extension]."\" />".$image."</td>";
					
						//check remote install status and define correct image and message
						foreach($this->remoteInstanceObjects as $inst) {
							
							$status = substr($this->remoteInstallStatus[$inst->name][$ext->extension], 0, strpos($this->remoteInstallStatus[$inst->name][$ext->extension], ':'));
							$installedVersion = substr($this->remoteInstallStatus[$inst->name][$ext->extension], strpos($this->remoteInstallStatus[$inst->name][$ext->extension], ':')+1);
							
							if( $status == "true") {
								$image = "<img src=\"components/com_easiv2/images/true.png\" />";
								$msg = "v".$installedVersion;
							}
							else {
								$image = "<img src=\"components/com_easiv2/images/false.png\" />";
								$msg = "";
							}
							
							//print out the installstatus. The checkboxes have the following value: 'extensionName:JoomlaInstance:intallStatus'
							echo "<td align=\"center\" valign=\"middle\"><input type=\"checkbox\" name=\"selected[]\" value=\"".$ext->extension.":".$inst->name.":".$this->remoteInstallStatus[$inst->name][$ext->extension]."\" />".$image."<br>".$msg."</td>";
							//$status = JHtml::_('grid.id', $ext->extension, $inst->id)."<img src=\"components/com_easiv2/images/false.png\" />";
						}
					echo "</tr>";
				}
			?>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="<?php echo count($this->remoteInstanceObjects)+2; //+2 because of the column 'Extension' and the obligatory column 'Magamenet Instance' ?>">Pagination?</td>
			</tr>
		</tfoot>
	</table>
	<input type="hidden" name="option" value="com_easiv2" />
	<input type="hidden" name="view" value="manageExtensions" />
	<input type="hidden" name="task" value="" />
</form>